<template>
  <el-table :data="filterTableData" style="width: 100%">
    <el-table-column label="Date" prop="createTime" />
    <el-table-column label="Name" prop="accountName" />
    <el-table-column align="right">
      <template #header>
        <el-input v-model="search" size="small" placeholder="Type to search" />
      </template>
      <template #default="scope">
        <el-button size="small" @click="handleEdit(scope.$index, scope.row)">
          Edit
        </el-button>
        <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
        >
          Delete
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue'

interface UserAdvice {
  id:number
  accountName:String,
  createTime:String
  problem:String
  advice:String
  contactPhone:String
  contactMail:String
}

const search = ref('')
const filterTableData = computed(() =>
    tableData.filter(
        (data) =>
            !search.value ||
            data.accountName.toLowerCase().includes(search.value.toLowerCase())
    )
)
const handleEdit = (index: number, row: UserAdvice) => {
  console.log(index, row)
}
const handleDelete = (index: number, row: UserAdvice) => {
  console.log(index, row)
}

const tableData: UserAdvice[] = [
  {
    createTime: '2016-05-03',
    accountName: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    createTime: '2016-05-02',
    accountName: 'John',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    createTime: '2016-05-04',
    accountName: 'Morgan',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    createTime: '2016-05-01',
    accountName: 'Jessy',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>
